package com.health.trans.common.entity;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * @author nqlz
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "翻页查询接口返回参数格式")
public class PageResponse<T> implements Serializable {

    private static final long serialVersionUID = -8810074712372408264L;

    @ApiModelProperty(value = "编码:成功返回200", example = "0")
    private Integer code = CodeEnum.SUCCESS.getCode();
    @ApiModelProperty(value = "提示信息")
    private String msg = "";
    @ApiModelProperty(value = "符合条件总条数", example = "10")
    private Long count;
    @ApiModelProperty(value = "数据")
    private T data;

    public static PageResponse OK(Long count, Object data) {

        return new PageResponse(CodeEnum.SUCCESS.getCode(), "", count, data);

    }

    public static PageResponse ERROR(String msg) {

        return new PageResponse(CodeEnum.SYSTEM_ERROR.getCode(), msg, 0L, null);

    }

    public static <R> PageResponse<R> success(Number count, Object data) {
        return PageResponse.OK(count.longValue(),data);
    }

    public static <R> PageResponse<R> fail(String msg) {
        return PageResponse.ERROR(msg);
    }
}
